import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'
import * as actionCreator from './store/actionCreator'

class Login extends PureComponent {
  render() {
    if(!this.props.login2){
      return <div>
        <input type="text" placeholder="zhanghao" ref={ (input) => this.account = input}/><br/>
        <input placeholder="mima" type="password" ref={ (input) => this.password = input} /><br/>
        <button onClick={() => {this.props.login(this.account, this.password)}}>denglu</button>  
      </div>
    }else{
      return <Redirect  to="/" />
    } 
  }
}
const mapStateToprops = (state) => {
  return {
    login2 : state.getIn(['login', 'login'])
  }
}

const mapDispathToprops = (dispatch) => {
  return {
    login(account, password){
      console.log(account.value)
      dispatch(actionCreator.login(account.value, password.value))
    }
  }
}

export default connect(mapStateToprops, mapDispathToprops )(Login)